package com.ssy.lingxi.member.merchant.test;


import com.alibaba.fastjson.JSONObject;
import com.ssy.lingxi.common.utils.DateUtil;
import com.ssy.lingxi.member.merchant.utils.baidu.IdCardUtil;

public class Idcard {


    public static void main(String[] args) {
    //    String s="https://shushangyun01.oss-cn-shenzhen.aliyuncs.com/1A2EC~10668f0d8346046568cf270f1df284251.jpg";
        //正面
        String s="https://shushangyun01.oss-cn-shenzhen.aliyuncs.com/微信图片_2022011009504431c2941eeb7f4a76b9b98256f61a8e4c.jpg";
        // s="https://shushangyun01.oss-cn-shenzhen.aliyuncs.com/微信图片_20220117094134bccc7078eea942fda9f44a3f5e881c42.jpg";
        String idcard = null;
        try {
            idcard = IdCardUtil.idCard(s, null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(idcard);
        JSONObject resp = JSONObject.parseObject(idcard);
        String wordsResult = resp.getString("words_result");
        JSONObject attributes = JSONObject.parseObject(wordsResult);
        String nameKey = attributes.getString("姓名");
        String cardNoKey = attributes.getString("公民身份号码");
        String addressKey = attributes.getString("住址");
        JSONObject nameResp = JSONObject.parseObject(nameKey);
        JSONObject cardNoResp = JSONObject.parseObject(cardNoKey);
        JSONObject addressResp = JSONObject.parseObject(addressKey);
        String name = nameResp.getString("words");
        String cardNo = cardNoResp.getString("words");
        String address = addressResp.getString("words");
        System.out.println("姓名:" + name);
        System.out.println("身份证号码:" + cardNo);
        System.out.println("住址:" +address);
        //反面
        String s1="https://shushangyun01.oss-cn-shenzhen.aliyuncs.com/微信图片_20220117094134bccc7078eea942fda9f44a3f5e881c42.jpg";
        String idcard1 = null;
        try {
            idcard1 = IdCardUtil.idCard(s1, null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(idcard1);
        JSONObject resp1 = JSONObject.parseObject(idcard1);
        String wordsResult1 = resp1.getString("words_result");
        JSONObject attributes1 = JSONObject.parseObject(wordsResult1);
        String expirationDate = attributes1.getString("失效日期");
        String dateOfIssue = attributes1.getString("签发日期");
        String issuingAuthority = attributes1.getString("签发机关");
        JSONObject expirationResp = JSONObject.parseObject(expirationDate);
        JSONObject dateOfIssueResp = JSONObject.parseObject(dateOfIssue);
        JSONObject issuingAuthorityResp = JSONObject.parseObject(issuingAuthority);
        Long expirationR = expirationResp.getLong("words");
        Long dateOfIssueR = dateOfIssueResp.getLong("words");
        String issuingAuthorityR = issuingAuthorityResp.getString("words");
        System.out.println("失效日期:" + expirationR);
        System.out.println("签发日期:" + dateOfIssueR);
        System.out.println("签发机关:" + issuingAuthorityR);

        long localDateTime = Long.parseLong(DateUtil.formatLocalDateTime());//当前日期
        if (localDateTime>=dateOfIssueR&& localDateTime<=expirationR){
            System.out.println("身份证有效");
        }
        String substring = issuingAuthorityR.substring(0, issuingAuthorityR.length() - 3);//XXX公安局
        System.out.println(substring);
        if (address.contains(substring)){
            System.out.println("身份证有效");
        }


    }
}